/*frontOceanTechnology123456
 * @描述:
 * @作者: 约訂
 * @Date: 2024-06-20 10:02:15
 * @LastEditTime: 2024-06-20 10:04:51
 * @修改人员: 约訂
 */
import CryptoJS from "crypto-js";

export default {
  // 加密
  encrypt(word, keyStr, ivStr) {
    keyStr = keyStr ? keyStr : "zheng1hai2ke3ji4";
    ivStr = ivStr ? ivStr : "zheng1hai2ke3ji4";
    let key = CryptoJS.enc.Utf8.parse(keyStr);
    let iv = CryptoJS.enc.Utf8.parse(ivStr);
    let srcs = CryptoJS.enc.Utf8.parse(word);

    let encrypted = CryptoJS.AES.encrypt(srcs, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.ZeroPadding,
    });
    return encrypted.toString();
  },
  // 解密
  decrypt(word, keyStr, ivStr) {
    keyStr = keyStr ? keyStr : "zheng1hai2ke3ji4";
    ivStr = ivStr ? ivStr : "zheng1hai2ke3ji4";
    var key = CryptoJS.enc.Utf8.parse(keyStr);
    let iv = CryptoJS.enc.Utf8.parse(ivStr);

    var decrypt = CryptoJS.AES.decrypt(word, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.ZeroPadding,
    });
    return decrypt.toString(CryptoJS.enc.Utf8);
  },
};
